<?php
/**
 * Created by PhpStorm.
 * User: mayn
 * Date: 2018/8/31
 * Time: 15:48
 */

namespace app\lib\exception;

use think\exception\Handle;
use think\Request;

class ExceptionHandler extends Handle
{
    private $code;
    private $msg;
    private $error_code;
    private $request_url;
    public function render(\Exception $e) {
        if ($e instanceof BaseException) {
            $this->code = $e->code;
            $this->error_code = $e->error_code;
            $this->msg = $e->msg;
        } else {
            return parent::render($e);
        }
        $request = Request::instance();
        $this->request_url = $request->url();
        return json([
            'msg' => $this->msg,
            'error_code' => $this->error_code,
            'request_url' => $this->request_url
        ],$this->code);
    }
}
